package com.bjgzy.rating.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bjgzy.rating.R;
import com.bjgzy.rating.mvp.contract.MyWorksContract;
import com.bjgzy.rating.mvp.model.MyWorksModel;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.MyWorksData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.jess.arms.di.scope.ActivityScope;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-8-30 20:32:07
 */
@Module
public class MyWorksModule {
    private MyWorksContract.View view;

    /**
     * 构建MyWorksModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public MyWorksModule(MyWorksContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    MyWorksContract.View provideMyWorksView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    MyWorksContract.Model provideMyWorksModel(MyWorksModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    List<MyWorksData> provideLists() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    RecyclerView.LayoutManager provideLayoutManager() {
        return new LinearLayoutManager(view.getActivity());
    }

    @ActivityScope
    @Provides
    BaseQuickAdapter<MyWorksData, AutoBaseViewHolder> providerAdapter(List<MyWorksData> lists) {
        return new BaseQuickAdapter<MyWorksData, AutoBaseViewHolder>(R.layout.rating_rv_item_my_works, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, MyWorksData item) {
                Glide.with(helper.itemView.getContext())
                        .load(item.getImg())
                        .apply(RequestOptions.placeholderOf(R.drawable.public_img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_logo));
                helper.setText(R.id.tv_name, item.getCreateName());
                helper.setText(R.id.tv_school, "(" + item.getCreateUnit() + ")");
                helper.setText(R.id.tv_title, item.getWorksName());
                helper.setText(R.id.tv_vote, item.getVoteCount() + " 票");
                helper.setText(R.id.tv_no, item.getResearchWorksNo());
                helper.setText(R.id.tv_status, item.getStatusStr());
                helper.setText(R.id.tv_time, TimeUtils.millis2String(item.getCreateTime(), new SimpleDateFormat("yyyy-MM-dd")));
            }
        };

    }
}